﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Web;
using System.Web.Services;
using System.Configuration;

namespace Pai.LiveStation.Web
{
    /// <summary>
    /// Summary description for MediaService
    /// </summary>
    [WebService(Namespace = "http://www.vivekrpai.com/livestation")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class MediaService : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public string UploadFile(byte[] f, string fileName)
        {
            try
            {
                MemoryStream ms = new MemoryStream(f);
                FileStream fs = new FileStream(System.Web.Hosting.HostingEnvironment.MapPath
                            ("~/" + ConfigurationManager.AppSettings["MediaLocation"] + "/") + fileName, FileMode.Create);
             
                ms.WriteTo(fs);

                ms.Close();
                fs.Close();
                fs.Dispose();

                return ConfigurationManager.AppSettings["MediaLocation"] + "/" + fileName;
            }

            catch (Exception ex)
            {

                // return the error message if the operation fails 
                //return ex.Message.ToString();
                
            }
            return null;
        }


    }
}
